﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package com.zynga.skelly.animation {
    import de.polygonal.ds.*;

	/**
	 * 维护一个AnimationList的双向列表 
	 */
    public class AnimationSchedule {

        private var m_listOfLists:DLinkedList;
        private var m_nextListToProcess:AnimationList;
        public var framesPerProcess:int;

        public function AnimationSchedule(_arg1:uint, _arg2:uint):void{
            var _local5:AnimationList;
            var _local6:DListNode;
            var _local7:DListNode;
            var _local8:DListNode;
            super();
            this.framesPerProcess = _arg1;
            this.m_listOfLists = new DLinkedList();
            var _local3:int;
            while (_local3 < _arg1) {
                this.m_listOfLists.append(new AnimationList(_arg1, _arg2, _local3));
                _local3++;
            };
            var _local4:DListIterator = this.m_listOfLists.getListIterator();
            _local4.start();
            while (_local4.data != null) {
                _local5 = _local4.data;
                _local6 = _local4.node;
                _local7 = null;
                if (_local6.next != null){
                    _local7 = _local6.next;
                };
                if (!_local7){
                    _local7 = this.m_listOfLists.head;
                };
                _local5.nextList = _local7.data;
                _local8 = null;
                if (_local6.prev != null){
                    _local8 = _local6.prev;
                };
                if (!_local8){
                    _local8 = this.m_listOfLists.tail;
                };
                _local5.prevList = _local8.data;
                if (_local4.next() == null){
                    break;
                };
            };
            this.m_nextListToProcess = this.m_listOfLists.head.data;
        }
        public function remove(_arg1:IAnimated):Boolean{
            var _local3:AnimationList;
            var _local2:DListIterator = this.m_listOfLists.getListIterator();
            _local2.start();
            while (_local2.data != null) {
                _local3 = _local2.data;
                if (_local3.contains(_arg1)){
                    _local3.remove(_arg1);
                    return (true);
                };
                _local2.next();
            };
            return (false);
        }
        public function add(_arg1:IAnimated):AnimationList{
            var _local7:int;
            var _local2:AnimationList = this.m_nextListToProcess.prevList;
            var _local3:int = _local2.m_animations.size;
            var _local4:int = this.m_listOfLists.size;
            var _local5:AnimationList = _local2.prevList;
            var _local6:int;
            while (((_local3) && ((_local6 < _local4)))) {
                _local7 = _local5.m_animations.size;
                if (_local7 < _local3){
                    _local2 = _local5;
                    _local3 = _local7;
                };
                _local6++;
                _local5 = _local5.prevList;
            };
            _local2.add(_arg1);
            this.m_nextListToProcess = _local2;
            return (_local2);
        }
        public function process(_arg1:uint):void{
            this.m_nextListToProcess.process(_arg1);
            this.m_nextListToProcess = this.m_nextListToProcess.nextList;
        }

    }
}//package com.zynga.skelly.animation 
